home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
SciAn
/
src
/
ScianRepobjFunctions.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
10KB
|
384 lines
/*ScianRepobjFunctions.c
Eric Pepke
10 August 1993
Does repobj functions, i.e., functions that work on individual windows'
REPOBJ variables.
*/
#include "Scian.h"
#include "ScianTypes.h"
#include "ScianLists.h"
#include "ScianWindows.h"
#include "ScianColors.h"
#include "ScianIDs.h"
#include "ScianObjWindows.h"
#include "ScianButtons.h"
#include "ScianErrors.h"
#include "ScianDraw.h"
#include "ScianControls.h"
#include "ScianArrays.h"
#include "ScianScripts.h"
#include "ScianVisWindows.h"
#include "ScianIcons.h"
#include "ScianEvents.h"
#include "ScianStyle.h"
#include "ScianRepobjFunctions.h"
#include "ScianHelp.h"
#include "ScianFilters.h"
#include "ScianFileSystem.h"
#include "ScianSockets.h"
#include "ScianPointers.h"
#include "ScianMenus.h"
#include "ScianPreferences.h"
#include "ScianFileSystem.h"
#include "ScianAnimation.h"
#include "ScianSymbols.h"
ObjPtr repobjActionClass;
typedef struct
{
char *name; /*Name of function*/
NameTyp message; /*Message to send to repobj*/
char *buttonHelp; /*Button help*/
char *menuHelp; /*Menu help*/
char *scriptLine; /*Line for script*/
ObjPtr menu; /*Which menu this routine is in*/
int menuGroup; /*Which menu group this function is in*/
} RepobjFunction;
int nRepobjFunctions = 0; /*# of repobj functions*/
static RepobjFunction *repobjFunctions;
#ifdef PROTO
int NameToRepobjFunction(char *name)
#else
int NameToRepobjFunction(name)
char *name;
#endif
/*Converts a name to a function number, or -1*/
{
int funcNum;
/*Search for the named function*/
for (funcNum = 0; funcNum < nRepobjFunctions; ++funcNum)
{
if (0 == strcmp2(name, repobjFunctions[funcNum] . name))
{
break;
}
}
if (funcNum >= nRepobjFunctions)
{
/*Not found, too bad.*/
char nameStr[300];
sprintf(nameStr, "Internal error: name '%s' not found", name);
ReportError("NameToRepobjFunction", nameStr);
return -1;
}
return funcNum;
}
#ifdef PROTO
Bool RepobjFunctionScriptLine(char *line)
#else
Bool RepobjFunctionScriptLine(line)
char *line;
#endif
/*If s is a script line, finds out if it is a valid script line for a
repobj function. If so, does it and returns true, otherwise does nothing
and returns false. Determines whether it is valid by matching the
script line*/
{
int funcNum;
register char *s, *p, *t;
/*For all possible functions*/
for (funcNum = 0; funcNum < nRepobjFunctions; ++funcNum)
{
/*Try to match script line against script*/
s = line;
p = repobjFunctions[funcNum] . scriptLine;
if (!p) continue;
SKIPBLANKS(s);
SKIPBLANKS(p);
while (*p)
{
if (isspace(*p))
{
SKIPBLANKS(s);
SKIPBLANKS(p);
}
else if (toupper(*p) != toupper(*s))
{
/*Failure to match*/
break;
}
else
{
++s;
++p;
}
}
if (*p == 0)
{
ObjPtr list;
ThingListPtr runner;
ObjPtr object;
/*It's a match! Do this function and return true*/
Log(repobjFunctions[funcNum] . scriptLine);
Log("\n");
object = GetVar((ObjPtr) selWinInfo, REPOBJ);
if (object)
{
DeferMessage(object, repobjFunctions[funcNum] . message);
}
return true;
}
}
return false;
}
#ifdef PROTO
void DefineRepobjFunction(char *funcName, NameTyp message,
char *scriptLine,
char *buttonHelp,
char *menuHelp, ObjPtr menu, int menuGroup)
#else
void DefineRepobjFunction(funcName, message, scriptLine,
buttonHelp, menuHelp, menu, menuGroup)
char *funcName;
NameTyp message;
char *scriptLine;
char *buttonHelp;
char *menuHelp;
ObjPtr menu;
int menuGroup;
#endif
/*Defines a repobj function
funcName is the name of the function for the menu and buttons
message is a message to do it
scriptLine is the script line
buttonHelp is the help string for a button, or nothing for no button
menuHelp is the help string for a menu
menu is which menu to use, or NULLOBJ for none
menuGroup is the menu group
*/
{
if (nRepobjFunctions)
{
repobjFunctions = Realloc(repobjFunctions, (nRepobjFunctions + 1) * sizeof(RepobjFunction));
}
else
{
repobjFunctions = Alloc((nRepobjFunctions + 1) * sizeof(RepobjFunction));
}
if (funcName)
{
repobjFunctions[nRepobjFunctions] . name = Alloc(strlen(funcName) + 1);
strcpy(repobjFunctions[nRepobjFunctions] . name, funcName);
}
else
{
repobjFunctions[nRepobjFunctions] . name = (char *) 0;
}
repobjFunctions[nRepobjFunctions] . message = message;
repobjFunctions[nRepobjFunctions] . menu = menu;
repobjFunctions[nRepobjFunctions] . menuGroup = menuGroup;
if (scriptLine)
{
repobjFunctions[nRepobjFunctions] . scriptLine = Alloc(strlen(scriptLine) + 1);
strcpy(repobjFunctions[nRepobjFunctions] . scriptLine, scriptLine);
}
else
{
repobjFunctions[nRepobjFunctions] . scriptLine = (char *) 0;
}
if (buttonHelp)
{
repobjFunctions[nRepobjFunctions] . buttonHelp = Alloc(strlen(buttonHelp) + 1);
strcpy(repobjFunctions[nRepobjFunctions] . buttonHelp, buttonHelp);
}
else
{
repobjFunctions[nRepobjFunctions] . buttonHelp = (char *) 0;
}
if (menuHelp)
{
repobjFunctions[nRepobjFunctions] . menuHelp = Alloc(strlen(menuHelp) + 1);
strcpy(repobjFunctions[nRepobjFunctions] . menuHelp, menuHelp);
}
else
{
repobjFunctions[nRepobjFunctions] . menuHelp = (char *) 0;
}
/*Put it on the appropriate menu*/
if (menu)
{
/*Put it on menu*/
ObjPtr action;
action = NewAction(funcName, repobjActionClass);
SetVar(action, HELPSTRING, NewString(menuHelp));
AddMenuItem(menu, action, menuGroup);
}
++nRepobjFunctions;
}
ObjPtr RepobjAction(action)
ObjPtr action;
/*Does the action method of a repobj action*/
{
int whichFunction;
ObjPtr var;
var = GetVar(action, NAME);
if (var)
{
whichFunction = NameToRepobjFunction(GetString(var));
if (contextHelp)
{
/*Give help on the action*/
ContextHelp(action);
contextHelp = false;
MySetCursor(0);
}
else
{
/*Log it*/
if (repobjFunctions[whichFunction] . scriptLine)
{
Log(repobjFunctions[whichFunction] . scriptLine);
Log("\n");
}
/*Do it*/
if (selWinInfo)
{
ObjPtr object;
object = GetVar((ObjPtr) selWinInfo, REPOBJ);
if (object)
{
DeferMessage(object, repobjFunctions[whichFunction] . message);
}
}
}
}
return ObjTrue;
}
static ObjPtr MakeRepobjActionActivated(action)
ObjPtr action;
/*Makes a repobj action activated*/
{
ObjPtr allSelected;
ThingListPtr runner;
int f;
ObjPtr var;
var = GetStringVar("MakeRepobjActionActivated", action, NAME);
if (!var) return ObjFalse;
f = NameToRepobjFunction(GetString(var));
if (f < 0) return ObjFalse;
if (selWinInfo)
{
ObjPtr object;
object = GetVar((ObjPtr) selWinInfo, REPOBJ);
if (object && GetMethod(object, repobjFunctions[f] . message))
{
SetVar(action, ACTIVATED, ObjTrue);
return ObjTrue;
}
}
SetVar(action, ACTIVATED, ObjFalse);
return ObjTrue;
}
#ifdef PROTO
void InitRepobjFunctions(void)
#else
void InitRepobjFunctions()
#endif
/*Initializes the repobj function system*/
{
int k;
char bHelpString[200], mHelpString[200], scriptString[40];
/*Make the class for repobj actions*/
repobjActionClass = NewObject(actionClass, 0L);
AddToReferenceList(repobjActionClass);
SetMethod(repobjActionClass, ACTIONMETHOD, RepobjAction);
SetVar(repobjActionClass, ACTIVATED, ObjFalse);
SetMethod(repobjActionClass, ACTIVATED, MakeRepobjActionActivated);
DeclareDependency(repobjActionClass, ACTIVATED, READYTOACTIVATE);
/*Define the actions*/
DefineRepobjFunction(RF_SAVEPALETTE, SAVECPANEL, "save controls",
"Pressing this button saves the palette in this control panel to a file.",
"Choosing this menu item saves the palette in this control panel to a file.",
colorMenu, 1);
DefineRepobjFunction(RF_KEEPPALETTE, KEEP, "keep",
"Pressing this button keeps the changes that you have made to the palette. \
Later, you can use Revert to Original to revert to this state.",
"Choosing this menu item keeps the changes that you have made to the palette. \
Later, you can use Revert to Original to revert to this state.",
colorMenu, 1);
DefineRepobjFunction(RF_REVERTPALETTE, REVERT, "revert",
"Pressing this button reverts the palette in the conrtol panel to the state it had the last time \
you chose Keep Changes, or to the original state if Keep Changes has not been chosen.",
"Choosing this menu item reverts the palette in the control panel to the state it had the last time \
you chose Keep Changes, or to the original state if Keep Changes has not been chosen.",
colorMenu, 1);
for (k = 0; k < NCOLORMODELS; ++k)
{
sprintf(scriptString, "model %s", colorModelNames[k]);
sprintf(bHelpString,
"Pressing this button converts the palette in the conrtol panel to the %s color model.",
colorModelNames[k]);
sprintf(mHelpString,
"Choosing this menu item converts the palette in the conrtol panel to the %s color model.",
colorModelNames[k]);
DefineRepobjFunction(colorModelNames[k], colorModelMethods[k],
scriptString, bHelpString, mHelpString, colorModelMenu, 1);
}
}
#ifdef PROTO
void KillRepobjFunctions(void)
#else
void KillRepobjFunctions()
#endif
/*Kills the repobj function system*/
{
int k;
for (k = 0; k < nRepobjFunctions; ++k)
{
SAFEFREE(repobjFunctions[k] . name);
SAFEFREE(repobjFunctions[k] . scriptLine);
SAFEFREE(repobjFunctions[k] . menuHelp);
SAFEFREE(repobjFunctions[k] . buttonHelp);
}
SAFEFREE(repobjFunctions);
RemoveFromReferenceList(repobjActionClass);
}